package com.rc.web.controller;

import com.mybatisflex.core.paginate.Page;
import com.rc.pojo.dto.knowledge.KnowLedgeAddDTO;
import com.rc.pojo.dto.knowledge.KnowLedgeUpdateDTO;
import com.rc.pojo.dto.knowledge.KnowledgePageQuery;
import com.rc.pojo.vo.knowldege.KnowledgePageVO;
import com.rc.pojo.vo.knowldege.KnowledgeVO;
import com.rc.web.service.KnowledgeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 员工信息 控制层。
 *
 * @author sym
 * @since 2024-05-24
 */
@Api(tags = "科普文章")
@RestController
@RequestMapping("/knowledge")
@RequiredArgsConstructor
public class KnowledgeController {
    private final KnowledgeService knowledgeService;

    @PostMapping
    @ApiOperation("新增")
    public void add(@RequestBody @Validated KnowLedgeAddDTO dto){
        knowledgeService.add(dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public void deleteById(@PathVariable Long id){
        knowledgeService.deleteById(id);
    }

    @PutMapping
    @ApiOperation("修改")
    public void updateOneById(@RequestBody @Validated KnowLedgeUpdateDTO dto){
        knowledgeService.updateOneById(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("农场管理员查看科普详情")
    public KnowledgeVO getOneById(@PathVariable Long id){
        return knowledgeService.getOneById(id);
    }

    @GetMapping("/page")
    @ApiOperation("农场管理员分页查看科普")
    public Page<KnowledgePageVO> getPage(KnowledgePageQuery dto) {
        return knowledgeService.getPage(dto);
    }

}
